package SEApp.components {
	import UIFree.uif_component;
	import UIFree.uif_ecomponent;
	import UIFree.uif_loader;
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filters.DropShadowFilter;

	public class se_loadProgress extends uif_ecomponent
	{
		private var _icon: *;
		private var _loadCount: int;
		private var _focus: Boolean; 
		public function se_loadProgress(parent:uif_component, imageClass: Class) {
			super(parent);
			mouseEnabled = false;
			uif_loader.disp = this;
			_loadCount 	= 0;
			_focus		= false;
			_icon = addChild(new imageClass());
			visible = false;
			addEvent(MouseEvent.MOUSE_MOVE, doMove, app);
			addEvent(MouseEvent.ROLL_OVER, doFocus, app);
			addEvent(MouseEvent.ROLL_OUT, doUnFocus, app);
// Запросы			
			addEvent(GDataEvent.REQUEST, doAddLoad, app);
			addEvent(GDataEvent.RESPONSE, doDecLoad, app);
// Загрузка картинок
			addEvent(GDataEvent.REQUESTIMAGE, doAddLoad, app);
			addEvent(GDataEvent.RESPONSEIMAGE, doDecLoad, app);
			addEvent(uif_loader.LD_LOAD, doAddLoad);
			addEvent(uif_loader.LD_COMPLETE, doDecLoad);
			addEvent(uif_loader.LD_ERROR, doDecLoad);
			
			filters = [new DropShadowFilter(3, 45, 0, 0.5, 5, 5, 1, 2)];
			visible = false;
			alpha = 0;
		}
		
		protected function doFocus(e: MouseEvent): void {
			_focus = true;
			resetPosition();
		}
		
		protected function doUnFocus(e: MouseEvent): void {
			_focus = false;
			resetPosition();
		}
		
		protected function doAddLoad(e: Event): void {
			if (!visible) resetPosition();
			_loadCount++;
			slideShow();
		}
		
		protected function doDecLoad(e: Event): void {
			_loadCount--;
			if (_loadCount <= 0) slideHide();
		}
		
		protected function resetPosition(): void {
			if (_focus) {
				x = parent.mouseX;
				y = parent.mouseY;
			} else position = app.center;
		}
		
		private function doMove(e: MouseEvent): void {
			if (visible) resetPosition();
		}
	}
}